package com.woniuxy.propertyjava.controller;


import com.woniuxy.propertyjava.entity.Cartype;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Patrolplan;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.CartypeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Cartype)表控制层
 *
 * @author makejava
 * @since 2022-07-06 09:59:34
 */
@RestController
@RequestMapping("cartype")
public class CartypeController {
    /**
     * 服务对象
     */
    @Resource
    private CartypeService cartypeService;

    /**
     * 分页查询
     *
     * @param cartype     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping("/cartype/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Cartype>> queryByPage(@RequestBody Cartype cartype,
                                                         @PathVariable int pageIndex,
                                                         @PathVariable int pageSize) {

        PageBean<Cartype> pageBean = new PageBean<>();

        pageBean=cartypeService.queryByPage(cartype,pageIndex,pageSize);
        ResponseResult<PageBean<Cartype>> responseResult = new ResponseResult<>();
        responseResult.setCode(200);
        responseResult.setMsg("查询成功");
        responseResult.setData(pageBean);
        return responseResult;
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/cartype/{id}")
    public ResponseResult<Cartype> queryById(@PathVariable("id") Integer id) {


        return new ResponseResult<>(200,"ok",cartypeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param cartype 实体
     * @return 新增结果
     */
    @PostMapping("/cartype")
    public ResponseResult<Cartype> add(@RequestBody Cartype cartype) {

        return new ResponseResult<>(200,"ok",cartypeService.insert(cartype));
    }

    /**
     * 编辑数据
     *
     * @param cartype 实体
     * @return 编辑结果
     */
    @PutMapping("/cartype")
    public ResponseResult<Cartype> edit(@RequestBody Cartype cartype) {
        return new ResponseResult<>(200,"ok",cartypeService.update(cartype));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseResult<Boolean> deleteById(Integer id) {
        return new ResponseResult<>(200,"ok",cartypeService.deleteById(id));
    }

}

